{include file="../../../application/admin/view/public/head" /}
<div class="page-container p10">
    <form class="layui-form layui-form-pane" method="post" action="">
        <input id="id" name="id" type="hidden" value="{$info.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">选择赛事：</label>
            <div class="layui-input-block">
                <div class="layui-input-inline">
                  <select name="type_id" lay-filter="saishitype" id="saishitype">
                  </select>
                </div>
                <div class="layui-input-inline">
                  <select name="game_id" lay-filter="saishicat" id="saishicat">
                  </select>
                </div>
            </div>
            <div class="layui-input-block" style="margin-top: 10px;">
              <select name="zhibo_id" lay-filter="saishilist" lay-verify="required" id="saishilist">
              </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">赛事图片：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="adpic" lay-verify="required" value="{$info.pic}" placeholder="请输入广告图片链接地址" name="pic">
                <a href="https://www.gudian.org/tools/tt.html" target="_blank" class="layui-btn" style="margin-top: 5px;">
                  <i class="layui-icon">&#xe67c;</i>上传赛事图片（宽750px，高370px）
                </a>
                <img src="{$info.pic}" class="yulantu" style="max-height: 100px;display: block;margin-top: 10px;" />
            </div>
        </div>
        <!--<div class="layui-form-item">-->
        <!--    <label class="layui-form-label">跳转链接：</label>-->
        <!--    <div class="layui-input-block">-->
        <!--        <input type="text" class="layui-input" lay-verify="required" value="{$info.jumpurl}" placeholder="请输入跳转链接" name="jumpurl">-->
        <!--    </div>-->
        <!--</div>-->
        <!--<div class="layui-form-item">-->
        <!--    <label class="layui-form-label">跳转方式：</label>-->
        <!--    <div class="layui-input-block" style="border: 1px solid #f1f1f1;">-->
        <!--        <input type="radio" name="jumpstatus" {if condition="$info['jumpstatus'] eq 0"}checked {/if} value="0" title="App内">-->
        <!--        <input type="radio" name="jumpstatus" {if condition="$info['jumpstatus'] eq 1"}checked {/if} value="1" title="App外">-->
        <!--    </div>-->
        <!--</div>-->

                <input type="text" style="display:none;" name="jumpstatus" value="1">
        <!--<div class="layui-form-item">-->
        <!--    <label class="layui-form-label">广告名称：</label>-->
        <!--    <div class="layui-input-block">-->
        <!--        <input type="text" class="layui-input" lay-verify="required" value="{$info.adname}" placeholder="请输入" name="adname">-->
        <!--    </div>-->
        <!--</div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">广告描述：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input addesc" class="layui-input" value="{$info.desc}" placeholder="请输入" name="desc">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">赛事顺序：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" value="{$info.saishishunxu}" placeholder="请输入赛事顺序" name="saishishunxu">
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">上推荐/发现：</label>
            <div class="layui-input-block" style="border: 1px solid #f1f1f1;">
                <input type="radio" name="from" {if condition="$info['from'] eq 0"}checked {/if} value="0" title="关闭">
                <input type="radio" name="from" {if condition="$info['from'] eq 1"}checked {/if} value="1" title="开启">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">轮播顺序：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" value="{$info.lunboshunxu}" placeholder="请输入轮播顺序(上推荐/发现开启后设置)" name="lunboshunxu">
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">状态：</label>
            <div class="layui-input-block" style="border: 1px solid #f1f1f1;">
                <input type="radio" name="status" {if condition="$info['status'] eq 0"}checked {/if} value="0" title="关闭">
                <input type="radio" name="status" {if condition="$info['status'] eq 1"}checked {/if} value="1" title="开启">
            </div>
        </div>

        <div class="layui-form-item center">
            <div class="layui-input-block">
                <input type="text" style="display:none" class="layui-input" value="0" placeholder="" name="adtype">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="formSubmit" data-child="true">保 存</button>
            </div>
        </div>
    </form>

</div>
{include file="../../../application/admin/view/public/foot" /}

<script type="text/javascript">
    layui.use(['form', 'jquery', 'layer'], function () {
        // 操作对象
        var form = layui.form
                , layer = layui.layer
                , $ = layui.jquery;
                
        function selectChangeCat(list, data, form) {
            var saishicatStr = "";
            var game_id = "{$info.game_id}";
            for(var i in list) {
                if(list[i].id == data && list[i].childs.length > 0) {
                    for(var j in list[i].childs) {
                        if(game_id == list[i].childs[j].game_id) {
                            saishicatStr += '<option value="' + list[i].childs[j].game_id + '" selected="selected">' + list[i].childs[j].name + '</option>';
                        } else {
                            saishicatStr += '<option value="' + list[i].childs[j].game_id + '">' + list[i].childs[j].name + '</option>';
                        }
                    }
                }
            }
            $("#saishicat").html(saishicatStr);
		    form.render('select');//select是固定写法 不是选择器
        }
        function selectChangeList(type_id, game_name, form) {
            // console.log(type_id, game_name, form)
            var data = {'jiami':-1, 'type_id':type_id};
            if(game_name != 0 && game_name != "") {
                data.game_name = game_name;
            }
            $("#saishilist").html("");
            form.render('select');//select是固定写法 不是选择器
            var index = layer.load(1);
            $.post("/app.php/zhibo/index", data, function(res) {
                layer.close(index); 
                // console.log(res)
                if(res.code == 1) {
                    var list = res.data.list;
                    if(list.length > 0) {
                        var saishiListStr = "";
                        var zhibo_id = "{$info.zhibo_id}";
                        for(var i in list) {
                            saishiListStr += '<option disabled="disabled">' + list[i].monthday + '</option>';
                            
                            if(list[i].list.length > 0) {
                                for(var j in list[i].list) {
                                    if(zhibo_id == list[i].list[j].zhibo_id) {
                                        saishiListStr += '<option value="' + list[i].list[j].zhibo_id + '" selected="selected">[' + list[i].list[j].zhibo_time_monthday + ' ' + list[i].list[j].zhibo_status_text + '] [' + list[i].list[j].zhibo_time_hour + '] ' + list[i].list[j].zhibo_name + ' [' + list[i].list[j].zhibo_qiudui.join(' vs ') +']</option>';
                                    } else {
                                        saishiListStr += '<option value="' + list[i].list[j].zhibo_id + '"> [' + list[i].list[j].zhibo_time_monthday + ' ' + list[i].list[j].zhibo_time_hour + '] [' + list[i].list[j].zhibo_status_text + '] ' + list[i].list[j].zhibo_name + ' [' + list[i].list[j].zhibo_qiudui.join(' vs ') +']</option>';
                                    }
                                }
                            }
                        }
                        // console.log(saishiListStr)
                        $("#saishilist").html(saishiListStr);
		                form.render('select');//select是固定写法 不是选择器
                        // $(".addesc").val($("#saishilist option:selected").html());
                    }
                }
            }, "json")
        }
        var index = layer.load(1);
        $.post("/app.php/zhibo/getType", {'jiami':-1}, function(res) {
            layer.close(index); 
            if(res.code == 1) {
                var list = res.data.list;console.log(list)
                if(list.length > 0) {
                    var saishitypeStr = "";
                    var info_type_id = "{$info['type_id']}";
                    var game_id = parseInt("{$info['game_id']}");
                    var data = 0;
                    var game_name = '';
                    
                    for(var i in list) {
                        if(list[i].id == info_type_id) {
                            data = list[i].id;
                            saishitypeStr += '<option value="' + list[i].id + '" selected="selected">' + list[i].name + '</option>';
                        } else {
                            saishitypeStr += '<option value="' + list[i].id + '">' + list[i].name + '</option>';
                        }
                        for(var j in list[i].childs) {
                            if(game_id == list[i].childs[j].game_id) {
                                game_name = list[i].childs[j].name;
                            }
                        }
                    }
                    if(data == 0) {
                        data = list[0].id;
                    }
                    $("#saishitype").html(saishitypeStr);
                    selectChangeCat(list, data, form);
                    selectChangeList(data, game_name, form);
                    form.on('select(saishitype)', function(data){
                        selectChangeCat(list, data.value, form);
                        selectChangeList(data.value, 0, form);
        			});
                    form.on('select(saishilist)', function(data){
                        $(".addesc").val($("#saishilist option:selected").html());
        			});
                    form.on('select(saishicat)', function(data){
                        var type_id = 0;
                        for(var i in list) {
                            if(list[i].childs.length > 0) {
                                for(var j in list[i].childs) {
                                    if(list[i].childs[j].game_id == data.value) {
                                        var type_id = list[i].childs[j].type_id;
                                        selectChangeList(type_id, list[i].childs[j].name, form);
                                    }
                                }
                            }
                        }
        			});
                    form.render();
                }
            }
        }, "json");
        
        $("#adpic").change(function() {
            $(".yulantu").attr("src", $(this).val());
        });
    });
</script>

</body>
</html>